<template>
  <BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose title="工艺建模"
    :width="!showContent ? 1440 : 1040" :closeFunc="closeFunc" @ok="handleSubmit">
    <div class="search_box" v-if="!showContent">
      <div class="search_item">
        <span>料品分类</span>
        <a-input-search v-model:value="searchParams.marbasclassName" placeholder="请选择料品分类" readonly
          style="width: 200px; margin-left: 10px" @search="openMarbasclass" />
      </div>
      <div class="search_item">
        <span>料号</span>
        <a-input-search v-model:value="searchParams.materialCode" placeholder="请选择料号" readonly
          style="width: 200px; margin-left: 10px" @search="openMaterial()" />
      </div>
      <div class="search_item">
        <a-checkbox v-model:checked="searchParams.isShowBom">单个产品展BOM</a-checkbox>
      </div>
      <div class="search_item">
        <a-button type="primary" @click="getBoomData">查询</a-button>
      </div>
      <div class="search_item">
        <a-button @click="reactSeach">重置</a-button>
      </div>
    </div>
    <div class="content" v-if="!showContent">
      <div class="left_box">
        <a-tabs type="card">
          <a-tab-pane key="productComponent" tab="产品组件">
            <div class="table_content">
              <a-table :scroll="{ x: 500, y: 300 }" :loading="productTable.productTableLoading"
                rowKey="materialNumberId" :row-selection="{ onChange: onChange }"
                :columns="productTable.productColumns" :data-source="productTable.productData" />
            </div>
          </a-tab-pane>
        </a-tabs>
      </div>
      <div class="right_box">
        <a-tabs type="card">
          <a-tab-pane key="processingTechnic" tab="加工工艺">
            <a-form ref="formRef" :model="processingTechnicForm"
              :label-col="{ style: { width: '100px' } }" @finish="onFinish" :rules="rules">
              <a-row :gutter="24">
                <!-- <a-col :span="12">
                  <a-form-item label="工艺分组">
                    <a-input-search v-model:value="processingTechnicForm.processGroupName"
                      placeholder="请选择工艺分组" readonly @search="openProcessGroup" />
                  </a-form-item>
                </a-col> -->
                <a-col :span="8">
                  <a-form-item label="工艺名称" name="processName" :colon="true">
                    <a-input-search :disabled="isDetail"
                      v-model:value="processingTechnicForm.processName" placeholder="请选择工艺" readonly
                      @search="openProcessManagement()" />
                  </a-form-item>
                </a-col>
                <a-col :span="8">
                  <a-form-item label="工艺顺序" :colon="true">
                    <a-select ref="select" v-model:value="processingTechnicForm.processOrder">
                      <a-select-option :value="item" v-for="item in selectData">{{
                        item
                      }}</a-select-option>
                    </a-select>
                  </a-form-item>
                </a-col>
                <a-col :span="8">
                  <a-form-item label="工作中心" name="workCenter" :colon="true">
                    <a-input-search :disabled="isDetail"
                      v-model:value="processingTechnicForm.workCenter" placeholder="请选择工作中心"
                      readonly @search="workCenterOpen" />
                  </a-form-item>
                </a-col>
              </a-row>
              <a-row :gutter="24">
                <a-col :span="8">
                  <a-form-item label="是否委外工序">
                    <a-checkbox v-model:checked="processingTechnicForm.outsourcingNot"></a-checkbox>
                  </a-form-item>
                </a-col>
                <a-col :span="8">
                  <a-form-item label="是否总装工序">
                    <a-checkbox v-model:checked="processingTechnicForm.finalAssembly"></a-checkbox>
                  </a-form-item>
                </a-col>
              </a-row>
              <a-row :gutter="24" style="border-top: 1px #ccc solid; padding-top: 20px">
                <a-col :span="12">
                  <a-form-item label="资源组" name="resourceGroup" :colon="true">
                    <a-input-search :disabled="isDetail"
                      v-model:value="processingTechnicForm.resourceGroup" readonly
                      placeholder="请选择资源组" @search="openResourceGrouping" />
                  </a-form-item>
                </a-col>
                <a-col :span="8">
                  <a-form-item label="单位产能" name="unitCapacity">
                    <a-input-number :disabled="isDetail" id="inputNumber" placeholder="请输入单位产能"
                      :min="0" v-model:value="processingTechnicForm.unitCapacity" />
                  </a-form-item>
                </a-col>
                <!-- <a-col :span="8">
                  <a-form-item label="用时单位"
                    <a-input-search :disabled="isDetail" @search="handleUnitView(1)" placeholder="请选择用时单位" readonly v-model:value="processingTechnicForm.timeUnit"></a-input-search>
                  </a-form-item>
                </a-col> -->
              </a-row>
              <a-row :gutter="24">
                <!-- <a-col :span="8">
                  <a-form-item label="单位">
                    <a-input-search
                      :disabled="isDetail"
                      @search="handleUnitView(2)"
                      placeholder="请选择单位"
                        readonly
                      v-model:value="processingTechnicForm.capacityUnitName"
                    ></a-input-search>
                  </a-form-item>
                </a-col> -->
                <a-col :span="8">
                  <a-form-item label="产能峰值">
                    <a-input-number :disabled="isDetail" placeholder="请输入产能峰值"
                      :min="0" v-model:value="processingTechnicForm.peakCapacity" />
                  </a-form-item>
                </a-col>
                <a-col :span="8">
                  <a-form-item label="前置时间" class="leadTimeAfter">
                    <a-input-number :disabled="isDetail" placeholder="请输入前置时间"
                      :min="0" v-model:value="processingTechnicForm.leadTime" />
                  </a-form-item>
                </a-col>
                <a-col :span="8">
                  <a-form-item label="工艺提前期" class="shiftHoursAfter">
                    <a-input-number :disabled="isDetail"  placeholder="请输入工艺提前期"
                      :min="0" v-model:value="processingTechnicForm.shiftHours" />
                  </a-form-item>
                </a-col>
              </a-row>
              <a-form-item :wrapper-col="{ offset: 20, span: 8 }">
                <a-button :disabled="isDetail" type="primary" html-type="submit">添加工艺</a-button>
              </a-form-item>
            </a-form>
          </a-tab-pane>
        </a-tabs>
      </div>
    </div>
    <div class="bottom">
      <a-tabs type="card">
        <a-tab-pane key="productProcess" tab="产品工艺">
          <div class="table_content">
            <a-table :scroll="{ x: 500, y: 300 }"
              :loading="productProcessTable.productProcessTableLoading"
              :columns="productProcessTable.productProcessColumns"
              :data-source="productProcessTable.productProcessData">
              <template #bodyCell="{ column, index, text, record }">
                <!-- 不加这个，非编辑模式时数据展示不出来 -->
                <template v-if="
                    [
                      'materialNumberCoding',
                      'materialNumberName',
                      'drawingNo',
                      'workCenter',
                      'processName',
                      'operationNumber',
                      'processOrder',
                      'outsourcingNot',
                      'finalAssembly',
                      'associationCode',
                      'associationName',
                      'resourcePriority',
                      'unitCapacity',
                      'leadTime',
                      'shiftHours',
                      'peakCapacity',
                    ].includes(column.dataIndex)
                  ">
                  <!-- 处于编辑模式下时，显示可操作列 -->
                  <div v-if="editTableData[record.id]">
                    <a-input-search v-if="['materialNumberCoding'].includes(column.dataIndex)"
                      v-model:value="editTableData[record.id][column.dataIndex]" placeholder="请选择料号"
                      readonly @search="openMaterial(record.id)" />
                    <a-input-search v-else-if="['workCenter'].includes(column.dataIndex)"
                      v-model:value="editTableData[record.id][column.dataIndex]"
                      placeholder="请选择工作中心" readonly @search="workCenterOpen(record.id)" />
                    <a-input-search v-else-if="['processName'].includes(column.dataIndex)"
                      v-model:value="editTableData[record.id][column.dataIndex]" placeholder="请选择工艺" readonly
                      @search="openProcessManagement(record.id)" />
                    <a-select v-else-if="['processOrder'].includes(column.dataIndex)" v-model:value="editTableData[record.id][column.dataIndex]">
                      <a-select-option :value="item" v-for="item in selectData">{{ item }}</a-select-option>
                    </a-select>                    
                    <a-select v-else-if="['outsourcingNot'].includes(column.dataIndex)" v-model:value="editTableData[record.id][column.dataIndex]">
                      <a-select-option :value="0">否</a-select-option>
                      <a-select-option :value="1">是</a-select-option>
                    </a-select>              
                    <a-select v-else-if="['finalAssembly'].includes(column.dataIndex)" v-model:value="editTableData[record.id][column.dataIndex]">
                      <a-select-option :value="0">否</a-select-option>
                      <a-select-option :value="1">是</a-select-option>
                    </a-select>
                    <a-input-number v-else-if="['unitCapacity','leadTime','peakCapacity','shiftHours'].includes(column.dataIndex)" v-model:value="editTableData[record.id][column.dataIndex]" placeholder="请输入"/>
                    <!-- 不允许编辑的数据 -->
                    <template v-else>
                      {{ text }}
                    </template>      
                  </div>
                </template>
                <template v-if="column.dataIndex === 'operation'">
                  <div class="editable-row-operations">
                  <!-- 点击编辑按钮后，不显示删除按钮 -->
                    <a style="color : #ED6F6F" @click="lineDel(index)" v-if="!editTableData[record.id]">删除</a>
                    <a-divider type="vertical" v-if="!editTableData[record.id]" />
                    <span v-if="editTableData[record.id]">
                      <a @click="lineSave(record.id)">保存</a>
                      <a-divider type="vertical" />
                      <a-popconfirm title="确定取消本次编辑吗？" @confirm="lineCancel(record.id)">
                        <a>取消</a>
                      </a-popconfirm>
                    </span>
                    <span v-else>
                      <a @click="lineEdit(record.id)">编辑</a>
                    </span>
                  </div>
                </template>
              </template>
            </a-table>
          </div>
        </a-tab-pane>
      </a-tabs>
    </div>
    <!-- 料品分类 -->
    <marbasclassSelectModel @register="marbasclassregModal"
      @getSelectResult="handleMarbasclassSuccess" v-bind="getBindValue"></marbasclassSelectModel>
    <!-- 料品 -->
    <materialSelectModel @register="materialRegModal" @getSelectResult="materialhandleSuccess"
      v-bind="getBindValue"></materialSelectModel>
    <!-- 工艺 -->
    <processManagementSelectModels @register="processManagementRegModals"
      @getSelectResult="processManagementhandleSuccesss" v-bind="getBindValue">
    </processManagementSelectModels>
    <!-- 工艺分组 -->
    <processGroupSelectModel @register="processGroupModals"
      @getSelectResult="processGroupHandleSuccesss" v-bind="getBindValue"></processGroupSelectModel>
    <!-- 单位 -->
    <unitSelectModel @register="unitRegModal" @getSelectResult="unithandleSuccess"
      v-bind="getBindValue"></unitSelectModel>
    <!-- 资源分组 -->
    <resourceGroupingSelectModel @register="resourceGroupingRegModal"
      @getSelectResult="resourceGroupingHandleSuccess" v-bind="getBindValue">
    </resourceGroupingSelectModel>
    <!-- 工作中心 -->
    <workCenterSelectModel @register="workCenterSelectModal"
      @getSelectResult="workCenterHandleSuccess" v-bind="getBindValue"></workCenterSelectModel>
  </BasicModal>
</template>

<script lang="ts" setup>
  import { ref, computed, unref, reactive, onMounted, onBeforeUnmount } from "vue";
  import { BasicModal, useModalInner, useModal } from "/@/components/Modal";
  import { BasicForm, useForm } from "/@/components/Form/index";
  import marbasclassSelectModel from "/@/views/components/marbasclassSelectModel.vue";
  import materialSelectModel from "/@/views/components/materialSelectModel.vue";
  import processManagementSelectModels from "/@/views/components/processManagementSelectModels.vue";
  import processGroupSelectModel from "/@/views/components/processGroupSelectModel.vue";
  import resourceGroupingSelectModel from "/@/views/components/resourceGroupingSelectModel.vue";
  import { productColumns, productProcessColumns } from "../PsProductProcess.data";
  import { getMaterialList, getQueryBomMaterial, saveOrUpdate, getQueryById, basResourceGroupDefinitionItemList, } from "../PsProductProcess.api";
  import unitSelectModel from "/@/views/components/unitSelectModel.vue";
  import workCenterSelectModel from "/@/views/components/workCenterSelectModel.vue";
  import { useMessage } from "/@/hooks/web/useMessage";
  import { cloneDeep } from "lodash-es";
  // import { basResourceGroupDefinitionItemList } from '/@/baseSetting/views/baseSetting/baseFiles/basResourceGroupDefinition/components/BasResourceGroupDefinition.api'
  const $message = useMessage();
  let timeType: number | null = null;
  // 定义当前编辑的列的索引，如果是打开的主表的选择器，就置undefined
  let activeMainBodyId: number | undefined = null;
  // Emits声明
  const emit = defineEmits(["register", "success"]);
  const getBindValue = Object.assign({}, "");
  const selectData = reactive([]);
  const formRef = ref < FormInstance > ();
  //  工艺顺序10-200
  for (let i = 10; i <= 200; i += 10) {
    selectData.push(i);
  }
  const rules = {
    processName: [{ required: true, message: "请选择工艺" }],
    workCenter: [{ required: true, message: "工作中心必填" }],
    resourceGroup: [{ required: true, message: "请选择资源组" }],
    unitCapacity: [{ required: true, message: "请输入单位产能" }],
  };

  // 搜索参数 响应式
  const searchParams = reactive({
    marbasclassName: "",
    marbasclassId: "",
    materialName: "",
    materialId: "",
  });

  // 加工工艺数据
  const processingTechnicForm = reactive <any> ({
    name: "",
    delivery: "",
    leadTime: "",
    unitCapacity: "",
    peakCapacity: "",
    outsourcingNot: 0,
    finalAssembly:0,
    processOrder: 10,
    shiftHours: 0
  });
  // 产品组件  响应式
  const productTable = reactive({
    productTableLoading: false,
    productData: [],
    selectedRows: [],
    productColumns: productColumns,
  });
  // 产品工艺
  const productProcessTable = reactive({
    productProcessTableLoading: false,
    productProcessData: [],
    productProcessColumns: productProcessColumns,
  });
  const isDetail = ref<boolean> (false);
  const showContent = ref<boolen> (false);
  const isUpdate = ref(true);
  //表单赋值
  const [registerModal, {
    setModalProps,
    closeModal
  }] = useModalInner(async (data) => {
    isDetail.value = !!data?.isDetail;
    isUpdate.value = !!data?.isUpdate;
    showContent.value = data.showContent;
    if (data.record?.id) {
      // 获取详情
      getDetail(data.record.id);
    }
    setModalProps({
      confirmLoading: false,
      showCancelBtn: !!data?.showFooter,
      showOkBtn: !!data?.showFooter,
    });
  });
  const editTableData: UnwrapRef < Record < string, DataItem >> = reactive({});
  // 注册料品分类选择框
  const [marbasclassregModal, {
    openModal: openMarbasclassModal
  }] = useModal();
  // 注册料品选择框
  const [materialRegModal, {
    openModal: openMaterialModal
  }] = useModal();
  // 注册工艺选择框
  const [ processManagementRegModals, { openModal: openProcessManagementModals } ] = useModal();
  // 注册工艺分组选择框
  const [ processGroupModals, { openModal: openProcessGroupModals }] = useModal();
  // 打开料品分类选择框
  function openMarbasclass() {
    openMarbasclassModal(true, {
      isUpdate: false,
      showFooter: true,
    });
  }
  // 注册单位筛选框
  const [ unitRegModal, { openModal: openUnitModal }] = useModal();
  // 注册资源组选择框
  const [ resourceGroupingRegModal, { openModal: openResourceGroupingModal }] = useModal();
  // 注册工作中心选择框
  const [ workCenterSelectModal, { openModal: openWorkCenterModal }] = useModal();
  //打开料品选择
  function openMaterial(id) {
    activeMainBodyId = id;
    openMaterialModal(true, {
      isUpdate: false,
      showFooter: true,
      marbasclassId: searchParams.marbasclassId,
    });
  }

  // 打开工艺选择
  function openProcessManagement(id) {
    activeMainBodyId = id;    
    openProcessManagementModals(true, {
      isUpdate: false,
      showFooter: true,
      processGroupId: processingTechnicForm.processGroupId,
      processGroupName: processingTechnicForm.processGroupName,
    });
  }
  // 打开工艺分组选择
  function openProcessGroup() {
    openProcessGroupModals(true, {
      isUpdate: false,
      showFooter: true,
    });
  }
  //打开单位选择
  function handleUnitView(type) {
    timeType = type; //1 用时单位 2 //产能单位
    openUnitModal(true, {
      isUpdate: false,
      showFooter: true,
    });
  }
  // 打开资源组选择
  function openResourceGrouping() {
    openResourceGroupingModal(true, {
      isUpdate: false,
      showFooter: true,
    });
  }
  //选择料品分类回写
  function handleMarbasclassSuccess(val, values) {
    searchParams.marbasclassName = val[0].item.name;
    searchParams.marbasclassId = val[0].item.id;
    
  }
  //料品回写
  function materialhandleSuccess(val, values) {
    // 回写子表料号
    if (activeMainBodyId) {
      editTableData[activeMainBodyId].materialNumberName = val[0].item.name;
      editTableData[activeMainBodyId].materialNumberId = val[0].item.id;
      editTableData[activeMainBodyId].materialNumberCoding = val[0].item.code;
    }
    // 回写顶部搜索的料号
    if (!activeMainBodyId) {
      console.log("valvalvalvalvalvalvalval",val)
      searchParams.materialName = val[0].item.name;
      searchParams.materialId = val[0].item.id;
      searchParams.materialCode = val[0].item.code;
    }
    console.log("activeMainBodyId",activeMainBodyId);
    console.log("searchParams",searchParams);
  }
  //工艺回写
  function processManagementhandleSuccesss(val, values) {
    // 回写子表工艺
    if(activeMainBodyId) {
      editTableData[activeMainBodyId].processName = val[0].item.processName;
      editTableData[activeMainBodyId].procedureId = val[0].item.id;
      editTableData[activeMainBodyId].operationNumber = val[0].item.processCoding;
    }
    // 回写加工工艺-工艺
    if(!activeMainBodyId) {
      processingTechnicForm.processName = val[0].item.processName;
      processingTechnicForm.procedureId = val[0].item.id;
      processingTechnicForm.operationNumber = val[0].item.processCoding;
      // 是否委外
      processingTechnicForm.whetherOutsourceProcess = val[0].item.whetherOutsourceProcess;
      // 工作中心
      processingTechnicForm.workCenter = val[0].item.workCenterName;
      processingTechnicForm.workCenterId = val[0].item.workCenterId;
    }
  }
  // 工艺分组回写
  function processGroupHandleSuccesss(val, values) {
    processingTechnicForm.processGroupId = val[0].item.id;
    processingTechnicForm.processGroupName = val[0].item.name;
  }
  // 打开工作中心模块
  function workCenterOpen(id) {
    activeMainBodyId = id;
    openWorkCenterModal(true, {
      isUpdate: false,
      showFooter: true,
    });
  }
  // 工作中心选择   工艺回写要回写工作中心
  function workCenterHandleSuccess(val, values) {
    // 子表工作中心回写
    if (activeMainBodyId) {
      editTableData[activeMainBodyId].workCenterId = val[0].item.id;
      editTableData[activeMainBodyId].workCenter = val[0].item.workCenterName;
    }
    // 回写加工工艺-工作中心
    if (!activeMainBodyId) {
      processingTechnicForm.workCenterId = val[0].item.id;
      processingTechnicForm.workCenter = val[0].item.workCenterName;
    }
  }
  //单位回写
  function unithandleSuccess(val, values) {
    if (timeType == 1) {
      processingTechnicForm.timeUnit = val[0].label;
      processingTechnicForm.timeUnitId = val[0].value;
    }
    if (timeType == 2) {
      processingTechnicForm.capacityUnitName = val[0].label;
      processingTechnicForm.capacityUnitId = val[0].value;
    }
    timeType = null;
  }
  // 资源分组筛选
  function resourceGroupingHandleSuccess(val, values) {
    processingTechnicForm.resourceGroupId = val[0].value;
    processingTechnicForm.resourceGroup = val[0].label;
    processingTechnicForm.resourceGroupCode = val[0].item.code;
  }
  // 获取选中的数据
  function onChange(selectedRowKeys, selectedRows) {
    productTable.selectedRows = selectedRows;
  }
  async function getDetail(id) {
    let params = {
      id: id,
    };
    const res = await getQueryById(params);
    productProcessTable.productProcessData.push(res);
  }

  const reactSeach = () => {
    searchParams.marbasclassName = null;
    searchParams.marbasclassId = null;
    searchParams.materialName = null;
    searchParams.materialId = null;
    getBoomData();
  };

  async function getBoomData() {
    productTable.productTableLoading = true;
    let tempArr = [];
    // 勾选 检索产品BOM
    if (searchParams.isShowBom) {
      let params = {
        materialId: searchParams.materialId,
      };
      const res = await getQueryBomMaterial(params);
      tempArr = res;
    }
    // 不勾选 检索料品档案
    else {
      let params = {
        id: searchParams.materialId,
      };
      const res = await getMaterialList(params);
      tempArr = res.records;
    }
    productTable.productData = !tempArr ?
      [] :
      tempArr.map((item) => {
        return {
          materialNumberId: item.id,
          materialNumberCoding: item.code,
          materialNumberName: item.name,
          spec: item.spec,
          materialTypeAttribute: item.materialTypeAttribute,
          drawingNo: item.drawingNo,
        };
      });
    productTable.productTableLoading = false;
  }

  async function onFinish() {
    if (productTable.selectedRows.length == 0) {
      $message.createMessage.warn("请先勾选产品组件!");
      return;
    }
    try {
      const values = await formRef.value.validate();
      let tempArr: any = [];
      productProcessTable.productProcessTableLoading = true;
      const res = await basResourceGroupDefinitionItemList({
        id: processingTechnicForm.resourceGroupId,
      });
      productTable.selectedRows.forEach((item: any) => {
        res.forEach((items: any, idx: number) => { 
          tempArr.push({
            processOrder: processingTechnicForm.processOrder,
            materialNumberId: item.materialNumberId,
            materialNumberCoding: item.materialNumberCoding,
            materialNumberName: item.materialNumberName,
            spec: item.spec,
            materialTypeAttribute: item.materialTypeAttribute,
            drawingNo: item.drawingNo,
            operationNumber: processingTechnicForm.operationNumber,
            processName: processingTechnicForm.processName,
            procedureId: processingTechnicForm.procedureId,
            outsourcingNot: processingTechnicForm.whetherOutsourceProcess ? 1 : 0,
            finalAssembly: processingTechnicForm.finalAssembly ? 1 : 0,
            resourceGroup: processingTechnicForm.resourceGroup,
            resourceGroupId: processingTechnicForm.resourceGroupId,
            resourceGroupCode: processingTechnicForm.resourceGroupCode,
            workCenter: processingTechnicForm.workCenter,
            workCenterId: processingTechnicForm.workCenterId,
            leadTime: processingTechnicForm.leadTime,
            shiftHours: processingTechnicForm.shiftHours,
            unitCapacity: processingTechnicForm.unitCapacity,
            peakCapacity: processingTechnicForm.peakCapacity,
            resourceGroupItemId: items.id,
            resourceGroupItemName: items.associationName,
            resourceGroupItemCode: items.associationCode,
          });
        });
      });
      productProcessTable.productProcessData = tempArr;
      productProcessTable.productProcessTableLoading = false;
    } catch (errorInfo) {
      console.log("Failed:", errorInfo);
    }
  }
  function lineDel(idx) {
    productProcessTable.productProcessData.splice(idx,1);    
  }
  function lineSave(id) {
    Object.assign(
      productProcessTable.productProcessData.filter((item) => id === item.id)[0],
      editTableData[id]
    );
    delete editTableData[id];
  }

  function lineCancel(id) {
    delete editTableData[id];
  }

  function lineEdit(id) {
    editTableData[id] = cloneDeep(
      productProcessTable.productProcessData.filter((item) => id === item.id)[0]
    );
  }
  //表单提交事件
  async function handleSubmit(v) {
    let len = productProcessTable.productProcessData.length > 0 ? false : true;
    if(len) {
      $message.createMessage.warning("产品工艺数据不能为空！");
      return;
    }
    // editTableData还有数据  代表并未保存
    let tempArr = Object.keys(editTableData);
    if (tempArr.length > 0) {
      $message.createMessage.warning("请先保存编辑的数据！");
      return;
    }
    try {
      setModalProps({
        confirmLoading: true,
      });
      let PsProductProcessPageObj;
      if (!isUpdate.value) {
        productProcessTable.productProcessData.forEach((item) => {
          delete item.id;
        });
        PsProductProcessPageObj = productProcessTable.productProcessData;
       
      } else  PsProductProcessPageObj = productProcessTable.productProcessData[0];
      //提交表单
      await saveOrUpdate(PsProductProcessPageObj, isUpdate.value);
      closeFunc();
      //关闭弹窗
      closeModal();
      //刷新列表
      emit("success");
    } finally {
      setModalProps({
        confirmLoading: false,
      });
    }
  }
  // 重置数据  并不影响响应式
  function clear(obj) {
    Object.keys(obj).forEach(item => {
      obj[item] = null
    })
  }
  function reset() {
    activeMainBodyId = null;    
    productProcessTable.productProcessData = [];
    productTable.productData = [];
    // 重置数据
    clear(searchParams);
    clear(processingTechnicForm);
  }

  function closeFunc() {
    // editTableData还有数据  代表并未保存
    let tempArr = Object.keys(editTableData);
    if (tempArr.length > 0) {
      $message.createMessage.warning("请先保存编辑的数据！");
      return false;
    }
    reset();
    return true;
  }

</script>

<style lang="less" scoped>
  /** 时间和数字输入框样式 */
  :deep(.ant-input-number) {
    width: 100%;
  }

  :deep(.ant-calendar-picker) {
    width: 100%;
  }

  .search_box {
    width: 100%;
    display: flex;

    .search_item {
      display: flex;
      align-items: center;
      margin-left: 15px;

      span {
        display: inline-flex;
        align-items: center;
        max-width: 100%;
        height: 32px;
        font-weight: 600;
        color: rgba(0, 0, 0, 0.85);
        font-size: 14px;
      }
    }
  }

  .content {
    display: flex;
    justify-content: space-between;
    padding-top: 20px;

    .left_box {
      width: 48%;
    }

    .right_box {
      width: 52%;
    }

    .left_box .table_content,
    :deep(.ant-tabs-tab-active) {
      color: #333333;
    }

    .leadTimeAfter::after {
      content: "（分钟）";
      align-items: center;
    }

    .shiftHoursAfter::after {
      content: "（小时）";
      align-items: center;
    }
  }

</style>